# for 循环结构
# 通常用于遍历数据容器
# 类似java里的 for each
# for 变量名 in 数据容器 :
#     for循环体代码
#     for循环体代码
#     for循环体代码
#     for循环体代码
list1 = [1, 2, 3, 4, 5]
for i in list1:
    print(i)
print("=" * 100)

tuple2 = (1, 2, 3, 4, 5)
for i in tuple2:
    print(i)
print("=" * 100)

set1 = {1, 2, 3, 4, 4, 5}
for i in set1:
    print(i)
print("=" * 100)

dict1 = {"k1": "v1", "k2": "v2", "k3": "v3"}
# 只能拿到key
for key in dict1:
    print(key)
print("=" * 100)

# 通过传入key 获取value 来实现遍历dict
for key in dict1:
    print(key, dict1[key])
print("=" * 100)

for key, value in dict1.items():
    print(key, value)
print("=" * 100)

list2 = [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
for i, j, k in list2:
    print(i, j, k)
print("=" * 100)

# zip()
list3 = ["a", "b", "c"]
list4 = [1, 2, 3]
for key, value in dict(zip(list3, list4)).items():
    print(key, value)
print("=" * 100)

# enumerate()
list5 = [1, 2, 3, 4, 5]
for i, j in enumerate(list5):
    print(i, j)
print("=" * 100)

# 列表推导式
# 用一段逻辑/代码去生成一个列表
list1 = [1, 2, 3, 4]
# 定义一个 1~100 的所有奇数的一个list
list2 = [i for i in range(1, 101) if i % 2 == 1]
print(list2)
print("=" * 100)

# 一行代码实现 9 9 乘法表
# range()
for i in range(1, 10):
    print(i)
print("=" * 100)

# 格式化字符串
# 一个数 * 一个数 = 一个值
# {} * {} = {}
str1 = "{} * {} = {}"
print(str1.format(9, 9, 81))
print("=" * 100)

# join方法
str3 = "#"
list3 = ["1", "2", "3"]
print(str3.join(list3))
print("=" * 100)

print("\n".join(["\t".join(["{}*{}={}".format(j, i, i * j) for j in range(1, i + 1)]) for i in range(1, 10)]))
